package org.colafries.metadata.driver;

import com.alibaba.druid.pool.DruidDataSource;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author colafries
 * @version v1.0
 * @ClassName DataSourcePool
 * @Description
 * @date Created in 2024/3/19
 **/
public class DataSourcePool {
    private static final Map<String, DruidDataSource> dataSourceMap = new ConcurrentHashMap<>();

    public static boolean exist(String key) {
        return dataSourceMap.containsKey(key);
    }

    public static Integer push(String key, DruidDataSource gainer) {
        dataSourceMap.put(key, gainer);
        return dataSourceMap.size();
    }

    public static Integer remove(String key) {
        dataSourceMap.remove(key);
        return dataSourceMap.size();
    }

    public static DruidDataSource get(String key) {
        return dataSourceMap.get(key);
    }
}
